package com.fiberhome.nas.core.network.datasource.photo

import com.fiberhome.nas.core.model.entity.PhotoInfo
import com.fiberhome.nas.core.model.entity.TimeBucketInfo
import com.fiberhome.nas.core.model.request.UploadRequest
import com.fiberhome.nas.core.model.response.ListData
import com.fiberhome.nas.core.model.response.NetworkResponse
import com.fiberhome.nas.core.model.response.UploadResult
import com.fiberhome.nas.core.network.base.BaseNetworkDataSource
import com.fiberhome.nas.core.network.service.PhotoService
import javax.inject.Inject

/**
 * 相册相关网络数据源
 */
class PhotoNetworkDataSourceImpl @Inject constructor(
    private val photoService: PhotoService
) : BaseNetworkDataSource(), PhotoNetworkDataSource {

    override suspend fun getTimeBuckets(
        size: String,
        albumId: String?,
        sceneId: String?,
        peopleId: String?
    ): NetworkResponse<ListData<TimeBucketInfo>> {
        return photoService.getTimeBuckets(
            size = size,
            albumId = albumId,
            sceneId = sceneId,
            peopleId = peopleId
        )
    }

    override suspend fun getTimeBucket(
        size: String,
        timeBucket: String,
        albumId: String?,
        sceneId: String?,
        peopleId: String?
    ): NetworkResponse<ListData<PhotoInfo>> {
        return photoService.getTimeBucket(
            size = size,
            timeBucket = timeBucket,
            albumId = albumId,
            sceneId = sceneId,
            peopleId = peopleId
        )
    }

    override suspend fun getPhotoInfo(photoId: String): NetworkResponse<PhotoInfo> {
        return photoService.getPhotoInfo(photoId)
    }

    override suspend fun uploadPhoto(uploadRequest: UploadRequest): NetworkResponse<UploadResult> {
        return photoService.uploadPhoto(
            deviceAssetId = uploadRequest.deviceAssetId!!,
            deviceId = uploadRequest.deviceId!!,
            fileName = uploadRequest.fileName,
            fileCreatedAt = uploadRequest.fileCreatedAt,
            fileModifiedAt = uploadRequest.fileModifiedAt,
            isFavorite = uploadRequest.isFavoriteStr!!,
            chunkOffset = uploadRequest.chunkOffsetStr,
            duration = uploadRequest.duration!!,
            chunkSize = uploadRequest.chunkSizeStr,
            chunkNumber = uploadRequest.chunkNumberStr,
            chunkHash = uploadRequest.chunkHash,
            totalChunk = uploadRequest.totalChunkStr,
            totalSize = uploadRequest.totalSizeStr,
            fileHash = uploadRequest.fileHash,
            hashAlgorithm = uploadRequest.hashAlgorithm,
            assetData = uploadRequest.createAssetDataPart()
        )
    }

}